package com.hjjt.cameralib.utils

import android.app.Application
import com.hjjt.baselib.provider.BaseContentContextProvider
import com.hjjt.cameraplugin.CameraEngineConfig
import java.io.File

/**
 *
 * @ProjectName:    CloudWalkPluginApk
 * @Package:        com.hjjt.cloudwalkpluginapk.utils
 * @ClassName:      SoloadUtil
 * @Description:
 * @Author:         孙浩
 * @CreateDate:     2022/6/10 13:08
 */
object SoLoadUtil {

    val dir by lazy {
        File(BaseContentContextProvider.mContext!!.getDir("libs", Application.MODE_PRIVATE), "camera")
    }

    val cloudWalkPath by lazy {
        listOf<String>(
            "${dir.absolutePath+File.separator}librknnrt.so",
            "${dir.absolutePath+File.separator}libcwusb100.so",
            "${dir.absolutePath+File.separator}libjpeg.so",
            "${dir.absolutePath+File.separator}libturbojpeg.so",
            "${dir.absolutePath+File.separator}libuvc.so",
            "${dir.absolutePath+File.separator}libzxczburn.so",
            "${dir.absolutePath+File.separator}libcrystal.so",
            "${dir.absolutePath+File.separator}libcwbase.so",
            "${dir.absolutePath+File.separator}libcwLog.so",
            "${dir.absolutePath+File.separator}libopencv_java3.so",
            "${dir.absolutePath+File.separator}libcwCameraDevice.so",
            "${dir.absolutePath+File.separator}libFaceAE.so",
            "${dir.absolutePath+File.separator}libCWUVCCamera.so",
            "${dir.absolutePath+File.separator}libjsoncpp.so",
            "${dir.absolutePath+File.separator}libDeepNetV2.so",
            "${dir.absolutePath+File.separator}libCwRecog.so",
            "${dir.absolutePath+File.separator}libcwCrypt.so",
            "${dir.absolutePath+File.separator}libsafechip_z.so",
            "${dir.absolutePath+File.separator}libcwauthorize_safechip_z.so",
            "${dir.absolutePath+File.separator}libcwAuthorized.so",
            "${dir.absolutePath+File.separator}libcwauthorize_android.so",
            "${dir.absolutePath+File.separator}libDetectLivenessModule.so",
            "${dir.absolutePath+File.separator}libcwLivEngine.so",
            "${dir.absolutePath+File.separator}libcwPackgeLayerEngine.so",
            "${dir.absolutePath+File.separator}libomp.so",
            "${dir.absolutePath+File.separator}libCWMiddlewareEngine.so"
        )
    }

    fun loadCameraSo(type: CameraEngineConfig.CameraEngineType) {
        when (type) {
            CameraEngineConfig.CameraEngineType.CLOUD_WALK -> loadCloudLoadSo()
            else -> {}
        }
    }

    private fun loadCloudLoadSo() {
        cloudWalkPath.forEach {
            System.load(it)
        }
    }
}